package com.dk.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.pojo.TCar;
import com.dk.pojo.TCarType;
import com.dk.service.ITCarTypeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 车辆分类表 前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-30
 */
@RestController
@RequestMapping("/t-car-type")
public class TCarTypeController {

    @Autowired
    private ITCarTypeService typeService;

    @ApiOperation(value = "车辆类型查询")
    @GetMapping
    public Result getInfoIdBy(){
       List<TCarType> list = typeService.getInfoAll();
        return Result.bulid(ConstantEnum.SUCCESS).setResult(list);
    }

    @ApiOperation(value = "车辆类型增加操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TCarType",value = "实体类:车辆类型",required = true,paramType = "body",dataTypeClass = TCarType.class)
    })
    @PostMapping("/add")
    public Result add(@RequestBody TCarType tCarType){

        tCarType.setCreateTime(new Date());
        tCarType.setUpdateTime(new Date());
        boolean b = typeService.save(tCarType);
        if(b){
            return Result.bulid(ConstantEnum.SUCCESS);
        }
        return Result.bulid(ConstantEnum.ERROR);
    }

    @ApiOperation(value = "车辆类型修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TCarType",value = "实体类:车辆类型",required = true,paramType = "body",dataTypeClass = TCarType.class)
    })
    @PutMapping(value = "/update")
    public Result getInfoId(@RequestBody TCarType tCarType){

        Integer i = typeService.updateInfo(tCarType);
        if(i>0){
            return Result.bulid(ConstantEnum.SUCCESS);
        }
        return Result.bulid(ConstantEnum.ERROR);
    }

    @ApiOperation(value = "车辆类型删除")
    @ApiImplicitParam(name = "ids",value = "车辆类型的ID",required = true,allowMultiple = true,dataType = "int")
    @DeleteMapping
    public Result del(@RequestParam("ids") Integer[] ids){
        List<Integer> list = new ArrayList<>();
        for (Integer id : ids) {
            list.add(id);
        }
        //批量删除
        boolean b = typeService.removeByIds(list);
        return Result.bulid(ConstantEnum.SUCCESS);
    }

}
